package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import lombok.extern.java.Log;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.DlJobDO;
import com.bootdo.system.service.DlJobService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-06-03 16:29:49
 */
 
@Controller
@Log
@RequestMapping("/system/dlJob")
public class DlJobController {
	@Autowired
	private DlJobService dlJobService;
	
	@GetMapping()
	@RequiresPermissions("system:dlJob:dlJob")
	String DlJob(){
	    return "system/dlJob/dlJob";
	}

	/**
	 * 功能描述: 遍历列表
	 * @Param: [params]
	 * @Return: com.bootdo.common.utils.PageUtils
	 * @Author: 况鑫威
	 * @Date: 2021/6/3
	 * @Time: 17:12
	 */
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:dlJob:dlJob")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DlJobDO> dlJobList = dlJobService.list(query);
		int count = dlJobService.count(query);
		PageUtils pageUtils = new PageUtils(dlJobList, count);
		return pageUtils;
	}

	@ResponseBody
	@PostMapping("/auditFailureText")
	public R auditFailureText(String jobId, String auditFailureText){
		log.info("职位id:"+jobId);
		log.info("失败原因:"+auditFailureText);
		return dlJobService.auditFailureText(jobId, auditFailureText);
	}

	/**
	 * 功能描述: 跳转添加页面
	 * @Param: []
	 * @Return: java.lang.String
	 * @Author: 况鑫威
	 * @Date: 2021/6/3
	 * @Time: 17:12
	 */
	@GetMapping("/add")
	@RequiresPermissions("system:dlJob:add")
	String add(){
	    return "system/dlJob/add";
	}

	/**
	 * 功能描述: 跳转修改页面
	 * @Param: []
	 * @Return: java.lang.String
	 * @Author: 况鑫威
	 * @Date: 2021/6/3
	 * @Time: 17:12
	 */
	@GetMapping("/edit/{jobId}")
	@RequiresPermissions("system:dlJob:edit")
	String edit(@PathVariable("jobId") Integer jobId,Model model){
		DlJobDO dlJob = dlJobService.get(jobId);
		model.addAttribute("dlJob", dlJob);
	    return "system/dlJob/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
//	@RequiresPermissions("system:dlJob:add")
	public R save( DlJobDO dlJob){
		if(dlJobService.save(dlJob)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
//	@RequiresPermissions("system:dlJob:edit")
	public R update(DlJobDO dlJob){
		log.info("职位ID" + dlJob.getJobId() + ("1".equals(dlJob.getAuditStatus())?"审核通过":"审核失败"));
		dlJobService.update(dlJob);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:dlJob:remove")
	public R remove( Integer jobId){
		if(dlJobService.remove(jobId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:dlJob:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] jobIds){
		dlJobService.batchRemove(jobIds);
		return R.ok();
	}
	
}
